package com.cn.integration;

import org.apache.log4j.Logger;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;

public class ApplicationEventHandler {
	/**
	 * 日志
	 */
	public Logger logger = Logger.getLogger(ApplicationEventHandler.class);

	/**
	 * 类别
	 */
	public String type;
	/**
	 * 通道
	 * @return
	 */
	private MessageChannel channel;

	/**
	 * 通道
	 * @return
	 */
	public MessageChannel getChannel() {
		return channel;
	}

	/**
	 * 类别
	 */
	public String getType() {
		return type;
	}

	/**
	 * 发送消息
	 * @param input
	 * @return
	 */
	public String send(String input) {
		Message<String> message = MessageBuilder.withPayload(input).build();
		this.getChannel().send(message);
		return "success";
	}

	/**
	 * 接受消息
	 * @param message
	 * @return
	 */
	public Message<String> receive(Message<String> message) {

		Message<String> result = MessageBuilder.fromMessage(message).build();
		logger.debug(message);
		return result;
	}

	public void setChannel(MessageChannel channel) {
		this.channel = channel;
	}

	public void setType(String type) {
		this.type = type;
	}
}
